import Taro, {Component} from '@tarojs/taro'
import {View} from '@tarojs/components'
import { connect } from '@tarojs/redux'
import styles from './index.module.scss'
import PREVIEW_BANNER from '@/assets/img/preview_banner.png'
import {confirmBySign} from '@/api/index'
import { setUrl } from '@/actions/web'

@connect(({user}) => ({
  info: user.info
}), dispatch => ({
  setUrl: (data) => dispatch(setUrl(data))
}))
export default class Preview extends Component {

  config = {
    navigationBarTitleText: '签约信息'
  }

  confirm = async () => {
    const { setUrl, info } = this.props
    const { mobile } = info
    try {
      Taro.showLoading({title: '签约中...', mask: true})
      const { data } = await confirmBySign({loginAccount: mobile})
      Taro.hideLoading()
      setUrl(data.url)
      Taro.navigateTo({url: '/pages/web/index'})
    } catch(e) {
      Taro.showToast({title: e.message, icon: 'none'})
    }
  }

  render () {
    return (
      <View className={styles.wrapper}>
        <Image src={PREVIEW_BANNER} className={styles.banner}></Image>
        <Button className={styles.confirm} onClick={this.confirm} >立即签约</Button>
      </View>
    )
  }
}
